package code.temp.log;

import java.awt.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;

/**
 * <b>Description : </b>
 *
 * @author CPF
 * @date 2020/10/30
 **/
public class ClipboardExercise {

    public static void main(String[] args) throws IOException {
//        Clipboard sysc = Toolkit.getDefaultToolkit().getSystemClipboard();
//        System.out.println(sysc);
        new Dialog("fjksdlkdf");
    }

    /**
     *3. 从剪切板获得图片。
     */
    public static Image getImageFromClipboard() throws IOException, UnsupportedFlavorException {
        Clipboard sysc = Toolkit.getDefaultToolkit().getSystemClipboard();
        Transferable cc = sysc.getContents(null);
        if (cc == null)
            return null;
        else if (cc.isDataFlavorSupported(DataFlavor.imageFlavor))
            return (Image) cc.getTransferData(DataFlavor.imageFlavor);
        return null;
    }

}
